package com.example.administrator.maizuofilm.cinemaschedule.utils;

import com.example.administrator.maizuofilm.bean.Actor;
import com.example.administrator.maizuofilm.bean.FilmList;
import com.example.administrator.maizuofilm.bean.Filmlist2;
import com.example.administrator.maizuofilm.bean.ForetellList;
import com.example.administrator.maizuofilm.bean.LineUp;
import com.example.administrator.maizuofilm.bean.PictureList;
import com.example.administrator.maizuofilm.bean.ShowList;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;


public class FilmListPaser {
   public  static List<FilmList>  paserByString(String str){
	   List<FilmList> list=new ArrayList<FilmList>();
	   try {
		JSONObject  object=new JSONObject(str);
		   JSONArray  array=object.getJSONArray("filmList");
		   for(int i=0;i<array.length();i++){
			   JSONObject  obj=array.getJSONObject(i);
			   FilmList  f=new FilmList();
			   
			  List<Actor> list2=new ArrayList<Actor>();
			  JSONArray  array2=obj.getJSONArray("actorInfo");
			  for(int x=0;x<array2.length();x++){
				  JSONObject obj2=array2.getJSONObject(x);
				  Actor  ac=new Actor();
				  ac.setActorName(obj2.getString("actorName"));
				  ac.setActorRole(obj2.getString("actorRole"));
				  ac.setPath(obj2.getString("path"));
				  list2.add(ac);
			  }
			  f.setActorInfo(list2);
			  f.setFilmID(obj.getString("filmID"));
			  f.setFilmName(obj.getString("filmName"));
			  f.setFilmType(obj.getString("filmType"));
			  f.setGrade(obj.getString("grade"));
			  f.setLanguage(obj.getString("language"));
			  f.setLength(obj.getString("length"));
			  JSONObject  obj3=obj.getJSONObject("lineUp");
			  LineUp lu=new LineUp();
			  lu.setBad(obj3.getString("bad"));
			  lu.setGood(obj3.getString("good"));
			  f.setLineUp(lu);
			  f.setNation(obj.getString("nation"));
			  List<PictureList> list3=new ArrayList<PictureList>();
			  JSONArray  array3=obj.getJSONArray("pictureList");
			  for(int j=0;j<array3.length();j++){
				  JSONObject  obj4=array3.getJSONObject(j);
				 PictureList pt=new PictureList();
				 pt.setPictureAddress(obj4.getString("pictureAddress"));
				 list3.add(pt);
			  }
			  f.setPictureList(list3);
			  f.setPrevueAddress(obj.getString("prevueAddress"));
			  f.setPosterAddress(obj.getString("posterAddress"));
			  f.setSynopsis(obj.getString("synopsis"));
			  list.add(f);
		   }
	} catch (JSONException e) {
		e.printStackTrace();
	}
	   
	   return  list;
   }
   public static List<ShowList> getCinemaSche(String json){
   	List<ShowList> list= new ArrayList<ShowList>();
       List<Filmlist2> flist=null;
       List<ForetellList> forlist=null;
       ShowList showList =null;
       Filmlist2 filmlist2 =null;
       ForetellList foretellList =null;
       try {
			JSONObject object =new JSONObject(json);
			JSONArray jsarrdata =object.getJSONArray("showList");
			for (int i = 0; i <jsarrdata.length(); i++) {
				JSONObject objdata =jsarrdata.getJSONObject(i);
				showList =new ShowList();
			    showList.setFilmID(objdata.getString("filmID"));
			    JSONArray jsarrflist =objdata.getJSONArray("filmlist");
			    flist = new ArrayList<Filmlist2>();
			    for (int j = 0; j < jsarrflist.length(); j++) {
					JSONObject objflist =jsarrflist.getJSONObject(j);
					filmlist2 =new Filmlist2();
					filmlist2.setShowDate(objflist.getString("showDate"));
					JSONArray jsarrforlist =objflist.getJSONArray("foretellList");
					forlist =new ArrayList<ForetellList>();
					for (int k = 0; k <jsarrforlist.length(); k++) {
						JSONObject object2 =jsarrforlist.getJSONObject(k);
						foretellList =new ForetellList();
						foretellList.setDimensional(object2.getString("dimensional"));
						foretellList.setFilmId(object2.getString("filmId"));
						foretellList.setFilmName(object2.getString("filmName"));
						foretellList.setHallName(object2.getString("hallName"));
						foretellList.setLanguage(object2.getString("language"));
						foretellList.setMarketPrice(object2.getString("marketPrice"));
						foretellList.setPrice(object2.getString("price"));
						foretellList.setShowTime(object2.getString("showTime"));
						foretellList.setShowDate(object2.getString("showDate"));
						foretellList.setCinemaId(object2.getString("cinemaId"));
						foretellList.setDuration(object2.getInt("duration"));
						foretellList.setForetellId(object2.getString("foretellId"));
						forlist.add(foretellList);
					}
					filmlist2.setFlist(forlist);
					flist.add(filmlist2);
				}
			    showList.setFilmlist2(flist);
				list.add(showList);
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
   	return list;
   }
}
